package com.zr.serviceimpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.OrderDao;
import com.zr.model.Cgoodstype;
import com.zr.model.Clogstate;
import com.zr.model.Corder;
import com.zr.model.Costate;
import com.zr.model.Cotype;
import com.zr.model.Cuser;
import com.zr.service.OrderService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service("orderService")
public class OrderServiceImpl implements OrderService{
   @Resource
	private OrderDao<Corder> showOrderDao;
	
	@Override
	public JSONObject getOrderInfo(int page, int rows,int uid) {
	  JSONObject  js=new JSONObject();
	  js.put("total",showOrderDao.getCountByoid(uid));
	  JSONArray jsa=new JSONArray();
	   List<Corder> li=showOrderDao.getAllOrderInfo(page, rows, uid);
	      for (Corder c : li) {
			JSONObject j=new JSONObject();
			j.put("oid", c.getOid());
			j.put("startp",c.getStartp());
			j.put("endp",c.getEndp());
			j.put("ostate", c.getCostate().getOstate());
			j.put("otype", c.getCotype().getOtype());
			j.put("logstate", c.getClogstate().getLogstate());
			j.put("osenddate", c.getOsenddate());
			j.put("osendman", c.getOsendman());
			j.put("sgetman", c.getSgetman());
			j.put("osendtel", c.getOsendtel());
			j.put("ogettel", c.getOgettel());
			j.put("paystate", c.getPaystate());
			j.put("paystyle", c.getPaystyle());
			j.put("goodsweight", c.getGoodsweight());
			j.put("goodsvolume", c.getGoodsvolume());
			j.put("goodsname", c.getGoodsname());
			j.put("goodsnumber", c.getGoodsnumber());
			j.put("valuation",c.getValuation());
			j.put("gtname",c.getCgoodstype().getGtname());
			j.put("barcode",c.getBarcode());
			jsa.add(j);
		}
	    js.put("rows",jsa);
	    System.out.println(js);
		return js;
	}

	@Override
	public int insertOrder(Corder corder,Cgoodstype goodstype,Clogstate logstate, Costate ostate,Cotype otype,int uid) {
		int i=showOrderDao.insertOrder(corder, goodstype, logstate, ostate, otype, uid);
		return i;
	}

	@Override
	public JSONObject getCurrentOrderInfo(int page, int rows, int disid) {
		JSONObject j=new JSONObject();
		j.put("rows",showOrderDao.getCurrentOrderInfo(page, rows, disid));
	//	j.put("total", showOrderDao.ge);
		return j;
	}

}
